<template>
  <div>
    <el-upload
      ref="upPhoto"
      :on-change="upPhoto"
      action="http://42.192.129.12:8888/api/private/v1/upload"
      list-type="picture">
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
  </div>
</template>

<script>
import { postPhoto } from '@/api/commodity'

export default {
  name: 'UpLoadPhoto',
  data () {
    return {}
  },
  methods: {
    async upPhoto (file) {
      // console.log(file)
      const fd = new FormData()
      fd.append('file', file.raw)
      try {
        await postPhoto(fd)
        // console.log(res.data)
      } catch (e) {
        console.log(e)
      }
      setTimeout(() => {
        this.$refs.upPhoto.clearFiles()
      }, 1000)
    }
  }
}
</script>

<style scoped>

</style>
